opendir
Open the directory handle
The opendir()
function opens the directory handle.
Open a directory, read its contents, and close:
<?php $dir = "/images/" ; // Open the directory and read its contents if ( is_dir ( $dir ) ) { if ( $dh = opendir ( $dir ) ) { while ( ( $file = readdir ( $dh ) ) !== false ) { echo "filename:" . $file . "<br>" ; } closedir ( $dh ) ; } } ?>
result:
filename: cat.gif filename: dog.gif filename: horse.gif
opendir ( path , context ) ;
parameter | describe |
---|---|
path | Required. Specify the directory path to open. |
context | Optional. Specifies the environment for directory handles. context is a set of options that can modify the behavior of a directory stream. |